#include <stdio.h>
#include <string.h>
#include <curses.h>
#include <stdbool.h>
#include "lib/parser.h"

#define MAZE_HEIGHT 9
#define MAZE_WIDTH 10

struct p{
    char *name;
    int hp;
    int maxHp;
    int keys;
    int attack;
    int def;
    int x;
    int y;
};
typedef struct p player_t;
player_t pl;
int viewMap[MAZE_HEIGHT][MAZE_WIDTH];

int main(void){
    //Parseo Enemies
    enemy_t *enemyList = (enemy_t *) malloc(sizeof(enemy_t));
    parseEnemies(enemyList);
    //Parseo Items
    item_t *itemList = (item_t *) malloc(sizeof(item_t));
    parseItems(itemList);
    //Parseo Boxes
    box_t *boxList = (box_t *) malloc(sizeof(box_t));
    parseBoxes(boxList);
    //
    room_t *rooms;
    parseRooms(MAZE_WIDTH, MAZE_HEIGHT, rooms);


    pl.attack = 100;
    pl.def = 30;
    pl.hp = 50;
    pl.keys = 0;
    pl.maxHp = 200;
    pl.name = "Juan Carlos";

    gameLoop(&rooms);
    return 0;
}

void gameLoop(room_t rooms){
    initscr();
    start_color();

    printStats();
    refresh();
getch();
    endwin();
}
void initViewMap(){
    int i,j;
    int height = MAZE_HEIGHT;
    int width  = MAZE_WIDTH;
    for(i=0; i<height; i++){
        for(j=0; j<width; j++){
            viewMap[i][j] = 0;
        }
    }
}
void printMap(){
    int startX = 0;
    int startY = 0;
    int height = MAZE_HEIGHT;
    int width  = MAZE_WIDTH;
    int i,j;
    char path = ACS_CKBOARD;
    char player = '@';
    init_pair(3, COLOR_YELLOW, COLOR_BLACK);

    viewMap[pl.y][pl.x] = 1;

    for(i=0; i<height; i++){
        for(j=0; j<width; j++){
             mvaddch(startY+i,startX+j,path);
        }
    }

    mvaddch(pl.y, pl.x, player);

}

//Corregir startX y startY para poder posicionar correctamente el recuadro de los stats
void printStats(){
    int startX=10;
    int startY=10;
    int height=10;
    int width = 17;

    int i,j;

    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_WHITE, COLOR_BLACK);

    attron(COLOR_PAIR(2));
    for(i=startX; i<=startX+width; i++){
       mvaddch(startY,i,ACS_HLINE);
       mvaddch(startY+height,i,ACS_HLINE);
    }
    for(i=startY; i<=startY+height; i++){
       mvaddch(i,startX,ACS_VLINE);
       mvaddch(i,startX+width,ACS_VLINE);
    }
    mvaddch(startY,startX,ACS_ULCORNER);
    mvaddch(startY+height,startX,ACS_LLCORNER);
    mvaddch(startY,startX+width,ACS_URCORNER);
    mvaddch(startY+height,startX+width,ACS_LRCORNER);

/*
    printw("Horizontal line           "); addch(ACS_HLINE); printw("  ACS_HLINE\n");
    printw("Vertical line             "); addch(ACS_VLINE); printw("  ACS_VLINE\n");
    printw("Upper left corner         "); addch(ACS_ULCORNER); printw("  ACS_ULCORNER\n");
    printw("Lower left corner         "); addch(ACS_LLCORNER); printw("  ACS_LLCORNER\n");
    printw("Upper right corner        "); addch(ACS_URCORNER); printw("  ACS_URCORNER\n");
    printw("Lower right corner        "); addch(ACS_LRCORNER); printw("  ACS_LRCORNER\n");
*/

    attron(COLOR_PAIR(1));
    startX++;
    mvprintw(++startY,startX,"%s", pl.name);
    mvprintw(++startY,startX,"---------------");
    mvprintw(++startY,startX,"HP: %d/%d", pl.hp, pl.maxHp);
    mvprintw(++startY,startX,"ATAQUE: %d", pl.attack);
    mvprintw(++startY,startX,"DEFENSA: %d", pl.def);
    mvprintw(++startY,startX,"LLAVES: %d", pl.keys);
}
